package net.cl7;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration //相当于spring配置的<beans>标签
@ConditionalOnBean(annotation = EnableDemoConfiguration.class) //加了此注释，当前类如果要被springboot实例化加载必须得在项目中有EnableDemoConfiguration注解
@EnableConfigurationProperties(DemoProperties.class) //开放属性配置入口，可以在yaml文件中配置DemoProperties的属性
public class DemoAutoConfiguration {

    @Bean  //在<beans>标签中定义<bean>
    @ConditionalOnMissingBean //当没有DemoService的实例的时候，是使用本方法实例化DemoService类
    DemoService demoService (){
        return new DemoService();
    }

}